package com.genexususa.eo.bing.data.requests;

import com.genexususa.eo.bing.CampaignManagementServiceClasses.Target;
import com.genexususa.eo.bing.data.GxItemException;
import com.genexususa.eo.bing.data.wsSubclasses.GxTarget;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class GxTargetRequest {
    private long gxCampaignId;
    private long bingCampaignId;
    private Target target;

    public GxTargetRequest(Element element) throws IllegalArgumentException, GxItemException {
        if (element.getElementsByTagName("GxCampaignId").getLength() > 0 &&
            element.getElementsByTagName("GxCampaignId").item(0).getChildNodes().getLength() > 0 &&
            Long.valueOf(((Node)element.getElementsByTagName("GxCampaignId").item(0).getChildNodes().item(0)).getNodeValue()) != 0) {
            this.gxCampaignId = Long.valueOf(((Node)element.getElementsByTagName("GxCampaignId").item(0).getChildNodes().item(0)).getNodeValue());
        } else {
            throw new GxItemException("Missing external Campaign id");
        }
        if (element.getElementsByTagName("BingCampaignId").getLength() > 0 &&
            element.getElementsByTagName("BingCampaignId").item(0).getChildNodes().getLength() > 0 &&
            Long.valueOf(((Node)element.getElementsByTagName("BingCampaignId").item(0).getChildNodes().item(0)).getNodeValue()) != 0) {
            this.bingCampaignId = Long.valueOf(((Node) element.getElementsByTagName("BingCampaignId").item(0).getChildNodes().item(0)).getNodeValue());
        } else {
            throw new GxItemException("Missing Bing Campaign id");
        }
        if (element.getElementsByTagName("Target").getLength() > 0 ) {
            this.target = new GxTarget((Element)element.getElementsByTagName("Target").item(0));
        }
    }

    public long getGxCampaignId() {
        return gxCampaignId;
    }

    public long getBingCampaignId() {
        return bingCampaignId;
    }

    public Target getTarget() {
        return target;
    }
}
